﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic;
using System.Web.Security;
using BusinessLogic.Statuses;

namespace WebSite.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);

            //if (!IsPostBack)
            {
                LoginUser.LoggingIn += new LoginCancelEventHandler(LoginUser_LoggingIn);
                LoginUser.LoggedIn += new EventHandler(LoginUser_LoggedIn);
            }
        }

        void LoginUser_LoggingIn(object sender, LoginCancelEventArgs e)
        {
            UserResultStatus res = new BLHelper().Login(LoginUser.UserName, LoginUser.Password);
            if (res.Status != ResultStatus.StatusType.Success)
            {
                e.Cancel = true;
            }
            else
            {
                Session["UserInfo"] = res.Data;
            }
        }

        protected void LoginUser_LoggedIn(object sender, EventArgs e)
        {
            Response.Redirect("~/Webinars.aspx");
        }
    }
}
